package com.sujie;

import java.util.Calendar;
import java.util.Timer;
import java.util.TimerTask;
import lombok.extern.java.Log;

/**
 * @author: xinmi
 * @date: 2020/11/24
 * @description:
 */
@Log
public class TimerMain {

    private static boolean firstTime = true;

    public static void main(String[] args) throws InterruptedException {
        Timer timer = new Timer();
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.HOUR_OF_DAY, Config.GPS_HOUR); //4点
        calendar.set(Calendar.MINUTE, Config.GPS_MINUTE);//45分
        calendar.set(Calendar.SECOND, Config.GPS_SECOND);//0秒

        log.info(calendar.getTime().toString());


        //每天的凌晨4:45,重新生成新文件
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                //每天定时生成新的文件路径和相应的输出流
                if(firstTime == false)
                    log.info("run in timer.");

            }
        }, calendar.getTime(), 24 * 60 * 60 * 1000);

        Thread.sleep(2000);
        firstTime = false;

        log.info("main thread end ");
    }
}
